package com.matching.controller;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.board.util.PagingUtil;
import com.matching.dao.MatchingDao;
import com.matching.domain.MatchingCommand;
import com.propose.domain.ProposeCommand;

@Controller
public class ManagingProposeController {

	private int pageSize = 10;
	private int blockCount = 10;
	
	@Autowired
	private MatchingDao matchingDao;
	
	@RequestMapping("/matching/proposeManager.do")
	public ModelAndView process(@RequestParam(value="pageNum",defaultValue="1")int currentPage,
								MatchingCommand matchingCommand){
		
		String pagingHtml = "";
		String state = "";
		
		Map<String,Object> map = new HashMap<String,Object>();
		
		//matchingDao.checkState();
		int count = matchingDao.getRowCount(matchingCommand);	
		
		PagingUtil page = new PagingUtil(null,null,
				currentPage,count,blockCount,pageSize,"list.do");
		
		pagingHtml = page.getPagingHtml().toString();
		
		map.put("start", page.getStartCount());
		map.put("end", page.getEndCount());
		
		List<MatchingCommand> list = null;
		if(count > 0){
			list = matchingDao.proposeList(map);
		}else{
			list = Collections.emptyList();
		}
		
		int number = count-(currentPage-1)*pageSize;
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName("proposeManagingList");
		mav.addObject("count", count);
		mav.addObject("list", list);
		mav.addObject("pagingHtml", pagingHtml);
		mav.addObject("number", number);
		mav.addObject("currentPage",currentPage);
		return mav;
		
	}
}